/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class PromotionBenefit
    {
    
        private String benefitTypeField;

        private String componentTypeField;

        private Decimal? quantityField;

        private Double? percentOffField;

        private  Price fixedAmountField;
        private  Price ceilingField;

        /// <summary>
        /// Gets and sets the BenefitType property.
        /// </summary>
        [XmlElementAttribute(ElementName = "BenefitType")]
        public String BenefitType
        {
            get { return this.benefitTypeField ; }
            set { this.benefitTypeField= value; }
        }



        /// <summary>
        /// Sets the BenefitType property
        /// </summary>
        /// <param name="benefitType">BenefitType property</param>
        /// <returns>this instance</returns>
        public PromotionBenefit WithBenefitType(String benefitType)
        {
            this.benefitTypeField = benefitType;
            return this;
        }



        /// <summary>
        /// Checks if BenefitType property is set
        /// </summary>
        /// <returns>true if BenefitType property is set</returns>
        public Boolean IsSetBenefitType()
        {
            return  this.benefitTypeField != null;

        }


        /// <summary>
        /// Gets and sets the ComponentType property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ComponentType")]
        public String ComponentType
        {
            get { return this.componentTypeField ; }
            set { this.componentTypeField= value; }
        }



        /// <summary>
        /// Sets the ComponentType property
        /// </summary>
        /// <param name="componentType">ComponentType property</param>
        /// <returns>this instance</returns>
        public PromotionBenefit WithComponentType(String componentType)
        {
            this.componentTypeField = componentType;
            return this;
        }



        /// <summary>
        /// Checks if ComponentType property is set
        /// </summary>
        /// <returns>true if ComponentType property is set</returns>
        public Boolean IsSetComponentType()
        {
            return  this.componentTypeField != null;

        }


        /// <summary>
        /// Gets and sets the Quantity property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Quantity")]
        public Decimal Quantity
        {
            get { return this.quantityField.GetValueOrDefault() ; }
            set { this.quantityField= value; }
        }



        /// <summary>
        /// Sets the Quantity property
        /// </summary>
        /// <param name="quantity">Quantity property</param>
        /// <returns>this instance</returns>
        public PromotionBenefit WithQuantity(Decimal quantity)
        {
            this.quantityField = quantity;
            return this;
        }



        /// <summary>
        /// Checks if Quantity property is set
        /// </summary>
        /// <returns>true if Quantity property is set</returns>
        public Boolean IsSetQuantity()
        {
            return  this.quantityField != null;

        }


        /// <summary>
        /// Gets and sets the PercentOff property.
        /// </summary>
        [XmlElementAttribute(ElementName = "PercentOff")]
        public Double PercentOff
        {
            get { return this.percentOffField.GetValueOrDefault() ; }
            set { this.percentOffField= value; }
        }



        /// <summary>
        /// Sets the PercentOff property
        /// </summary>
        /// <param name="percentOff">PercentOff property</param>
        /// <returns>this instance</returns>
        public PromotionBenefit WithPercentOff(Double percentOff)
        {
            this.percentOffField = percentOff;
            return this;
        }



        /// <summary>
        /// Checks if PercentOff property is set
        /// </summary>
        /// <returns>true if PercentOff property is set</returns>
        public Boolean IsSetPercentOff()
        {
            return  this.percentOffField != null;

        }


        /// <summary>
        /// Gets and sets the FixedAmount property.
        /// </summary>
        [XmlElementAttribute(ElementName = "FixedAmount")]
        public Price FixedAmount
        {
            get { return this.fixedAmountField ; }
            set { this.fixedAmountField = value; }
        }



        /// <summary>
        /// Sets the FixedAmount property
        /// </summary>
        /// <param name="fixedAmount">FixedAmount property</param>
        /// <returns>this instance</returns>
        public PromotionBenefit WithFixedAmount(Price fixedAmount)
        {
            this.fixedAmountField = fixedAmount;
            return this;
        }



        /// <summary>
        /// Checks if FixedAmount property is set
        /// </summary>
        /// <returns>true if FixedAmount property is set</returns>
        public Boolean IsSetFixedAmount()
        {
            return this.fixedAmountField != null;
        }




        /// <summary>
        /// Gets and sets the Ceiling property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Ceiling")]
        public Price Ceiling
        {
            get { return this.ceilingField ; }
            set { this.ceilingField = value; }
        }



        /// <summary>
        /// Sets the Ceiling property
        /// </summary>
        /// <param name="ceiling">Ceiling property</param>
        /// <returns>this instance</returns>
        public PromotionBenefit WithCeiling(Price ceiling)
        {
            this.ceilingField = ceiling;
            return this;
        }



        /// <summary>
        /// Checks if Ceiling property is set
        /// </summary>
        /// <returns>true if Ceiling property is set</returns>
        public Boolean IsSetCeiling()
        {
            return this.ceilingField != null;
        }






        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetBenefitType()) {
                xml.Append("<BenefitType>");
                xml.Append(EscapeXML(this.BenefitType));
                xml.Append("</BenefitType>");
            }
            if (IsSetComponentType()) {
                xml.Append("<ComponentType>");
                xml.Append(EscapeXML(this.ComponentType));
                xml.Append("</ComponentType>");
            }
            if (IsSetQuantity()) {
                xml.Append("<Quantity>");
                xml.Append(this.Quantity);
                xml.Append("</Quantity>");
            }
            if (IsSetPercentOff()) {
                xml.Append("<PercentOff>");
                xml.Append(this.PercentOff);
                xml.Append("</PercentOff>");
            }
            if (IsSetFixedAmount()) {
                Price  fixedAmount = this.FixedAmount;
                xml.Append("<FixedAmount>");
                xml.Append(fixedAmount.ToXMLFragment());
                xml.Append("</FixedAmount>");
            } 
            if (IsSetCeiling()) {
                Price  ceiling = this.Ceiling;
                xml.Append("<Ceiling>");
                xml.Append(ceiling.ToXMLFragment());
                xml.Append("</Ceiling>");
            } 
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}